import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
    {
        path: '/login',
        component: () => import('@/views/login/index'),
        hidden: true
    },

    {
        path: '/404',
        component: () => import('@/views/404'),
        hidden: true
    },
    {
        path: '/',
        component: Layout,
        name: 'Home',
        redirect: '/escortList',
        children: [
            {
                name: 'escortList',
                path: '/escortList',
                component: () => import('@/views/driverList/escortList.vue'),
                meta: {
                    title: '押运员信息管理'
                }
            }
        ]
    },
    {
        name: 'driverList',
        path: '/driverList',
        component: Layout,
        children: [
            {
                name: 'driverList',
                path: '/driverList',
                component: () => import('@/views/driverList/index.vue'),
                meta: {
                    title: '驾驶员信息管理'
                }
            }
        ]
    },
    {
        name: 'examination',
        path: '/examination',
        component: Layout,
        children: [
            {
                name: 'examination',
                path: '/examination',
                component: () => import('@/views/examination/index.vue'),
                meta: {
                    title: '考试记录'
                }
            }
        ]
    },
    {
        name: 'course',
        path: '/course',
        component: Layout,
        children: [
            {
                name: 'course',
                path: '/course',
                component: () => import('@/views/examination/course.vue'),
                meta: {
                    title: '课程管理'
                }
            }
        ]
    },
    {
        name: 'line',
        path: '/line',
        component: Layout,
        children: [
            {
                name: 'line',
                path: '/line',
                component: () => import("@/views/vehicle/line.vue"),
                meta: {
                    title: '行车日志'
                }
            }
        ]
    },
    {
        name: 'stockRecord',
        path: '/stockRecord',
        component: Layout,
        children: [
            {
                name: 'stockRecord',
                path: '/stockRecord',
                component: () => import("@/views/stockRecord/index.vue"),
                meta: {
                    title: '出入库记录'
                }
            }
        ]
    },
    {
        name: 'hint',
        path: '/hint',
        component: Layout,
        children: [
            {
                name: 'hint',
                path: '/hint',
                component: () => import("@/views/vehicle/hint.vue"),
                meta: {
                    title: '出车提示'
                }
            }
        ]
    },
    {
        path: '/settings',
        component: Layout,
        name: "settings",
        children: [
            {
                name: "setting",
                path: "/settings",
                component: () => import("@/views/settings/index.vue"),
                meta: {
                    title: "设置"
                },
            },
        ]
    },
    /*
    {
      path: '/merchant',
      component: Layout,
      name: "merchant",
      children: [
        {
          name: "merchant",
          path: "/merchant",
          component: () => import("@/views/merchant/escortList.vue"),
          meta: {
            title: "商家管理",
            icon: 'el-icon-s-shop'
          },
        },
      ]
    },
    {
      path: '/star',
      component: Layout,
      name: "star",
      children: [
        {
          name: "star",
          path: "/star",
          component: () => import("@/views/star/escortList.vue"),
          meta: {
            title: "星星禁用饮料管理",
            icon: 'el-icon-star-off'
          },
        },
      ]
    },
    {
      path: '/couponLink',
      component: Layout,
      name: "couponLink",
      children: [
        {
          name: "couponLink",
          path: "/couponLink",
          component: () => import("@/views/couponLink/escortList.vue"),
          meta: {
            title: "券链接管理",
            icon: 'el-icon-paperclip'
          },
        },
      ]
    },
    {
      path: '/managementList',
      component: Layout,
      name: "Management",
      children: [
        {
          name: "Management",
          path: "/managementList",
          component: () => import("@/views/management/escortList.vue"),
          meta: {
            title: "员工管理",
            icon: 'el-icon-s-custom'
          },
        },
      ]
    },
    {
      path: '/shop',
      component: Layout,
      name: "shop",
      children: [
        {
          name: "shop",
          path: "/shop",
          component: () => import("@/views/shop/escortList.vue"),
          meta: {
            title: "门店查询",
            icon: 'el-icon-s-shop'
          },
        },
      ]
    },*/
    // 404 page must be placed at the end !!!
    {path: '*', redirect: '/404', hidden: true}
]

const createRouter = () =>
    new Router({
        mode: 'history', // require service support
        scrollBehavior: () => ({y: 0}),
        routes: constantRoutes
    })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
